package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsCoupon;
import com.gs.gaosheng.service.GsCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/coupon")
public class GsCouponController extends BaseController
{
    @Autowired
    private GsCouponService gsCouponService;

    /**
     * 查询优惠券列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsCoupon gsCoupon)
    {
        startPage();
        List<GsCoupon> list = gsCouponService.selectGsCouponList(gsCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠券列表
     */
    @Log(title = "优惠券", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsCoupon gsCoupon)
    {
        List<GsCoupon> list = gsCouponService.selectGsCouponList(gsCoupon);
        ExcelUtil<GsCoupon> util = new ExcelUtil<GsCoupon>(GsCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    /**
     * 获取优惠券详细信息
     */
    @GetMapping(value = "/{couponId}")
    public AjaxResult getInfo(@PathVariable("couponId") Long couponId)
    {
        return AjaxResult.success(gsCouponService.selectGsCouponById(couponId));
    }

    /**
     * 新增优惠券
     */
    @Log(title = "优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsCoupon gsCoupon)
    {
        return toAjax(gsCouponService.insertGsCoupon(gsCoupon));
    }

    /**
     * 修改优惠券
     */
    @Log(title = "优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsCoupon gsCoupon)
    {
        return toAjax(gsCouponService.updateGsCoupon(gsCoupon));
    }

    /**
     * 删除优惠券
     */
    @Log(title = "优惠券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponIds}")
    public AjaxResult remove(@PathVariable Long[] couponIds)
    {
        return toAjax(gsCouponService.deleteGsCouponByIds(couponIds));
    }
}
